package com.feicai.aiagent.Advisor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.advisor.api.*;
import reactor.core.publisher.Flux;

@Slf4j
public class MyloggerAdvisor implements CallAroundAdvisor {
    public AdvisedRequest before(AdvisedRequest advisedRequest){
        log.info("before user: {}", advisedRequest.userText());
        return advisedRequest;
    }
    public void after(AdvisedResponse advisedResponse) {
        log.info("after AI: {}",advisedResponse.response().getResult().getOutput().getText());
    }
    @Override
    public AdvisedResponse aroundCall(AdvisedRequest advisedRequest, CallAroundAdvisorChain chain) {
        advisedRequest = this.before(advisedRequest);
        AdvisedResponse advisedResponse = chain.nextAroundCall(advisedRequest);
        this.after(advisedResponse);
        return advisedResponse;
    }



    @Override
    public String getName() {
        return this.getClass().getName();
    }

    @Override
    public int getOrder() {
        return 100;
    }
}
